import os
import scannet_200_classes

def generate_label_csv(input_file, ouput_file):
    '''
    生成类别标签文件，用于查询类型名称、是否是实例或背景
    '''
    classes = scannet_200_classes.get_class_labels(input_file)
    with open(ouput_file, 'w') as f:
        f.write('InstanceID,ClassID,PanopticID,R,G,B,Name,Size\n')
        for i, class_label in enumerate(classes):
            instance_id = i
            class_id = i
            panoptic_id = 1 if class_label.is_thing else 0  # 1 代表实例物体，0 代表背景
            r = class_label.color[0]
            g = class_label.color[1]
            b = class_label.color[2]
            class_name = class_label.name
            size = class_label.size
            f.write(f'{instance_id},{class_id},{panoptic_id},{r},{g},{b},{class_name},{size}\n')

if __name__ == '__main__':
    ouput_file = "/home/zxw/dataset/semantic/self_collect/for_panoptic_mapping/realsense_labels.csv"
    # 获取当前脚本所在目录
    current_dir = os.path.dirname(os.path.abspath(__file__))
    # 构建 class_label.csv 路径
    input_file = os.path.join(current_dir, '..', 'config', 'class_label.csv')
    generate_label_csv(input_file, ouput_file)